//
//  BIZOfflineCalendarView.m
//  biz
//
//  Created by zhangfuwei on 2017/4/18.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZOfflineCalendarView.h"

@implementation BIZOfflineCalendarView{
    UILabel     *_topSeverLab;
    UIButton    *_topDateBtn;
    
    UILabel     *_bottomSeverLab;
    UIButton    *_bottomDateBtn;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self loadUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self loadUI];
    }
    return self;
}


- (void)loadUI {
    _topSeverLab            = [[UILabel alloc] init];
    _bottomSeverLab         = [[UILabel alloc] init];
    _topSeverLab.text       = @"服务开始时间:";
    _bottomSeverLab.text    = @"服务结束时间:";
    _topSeverLab.textColor  = HEXCOLOR(0x666666);
    _topSeverLab.font       = CHINESE_SYSTEM(14);
    _bottomSeverLab.textColor  = HEXCOLOR(0x666666);
    _bottomSeverLab.font       = CHINESE_SYSTEM(14);

    _topDateBtn = [[UIButton alloc] init];
    _bottomDateBtn = [[UIButton alloc] init];
    [_topDateBtn setTitleColor:HEXCOLOR(0x666666) forState:UIControlStateNormal];
    [_bottomDateBtn setTitleColor:HEXCOLOR(0x666666) forState:UIControlStateNormal];

    _topDateBtn.titleLabel.font = CHINESE_SYSTEM(14);
    _bottomDateBtn.titleLabel.font = CHINESE_SYSTEM(14);

    _topDateBtn.tag = 0;
    _bottomDateBtn.tag = 1;


    [_topDateBtn setBackgroundImage:[UIImage imageNamed:@"offline_questionSubmit"] forState:UIControlStateNormal];
    [_topDateBtn setTitle:@"请选择开始时间" forState:UIControlStateNormal];
    [_topDateBtn addTarget:self action:@selector(dropDwonButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomDateBtn setBackgroundImage:[UIImage imageNamed:@"offline_questionSubmit"] forState:UIControlStateNormal];
    [_bottomDateBtn setTitle:@"请选择结束时间" forState:UIControlStateNormal];
    [_bottomDateBtn addTarget:self action:@selector(dropDwonButtonClick:) forControlEvents:UIControlEventTouchUpInside];

    
    [self addSubview:_bottomSeverLab];
    [self addSubview:_bottomDateBtn];
    
    [self addSubview:_topSeverLab];
    [self addSubview:_topDateBtn];
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat kViewMargin = 15;
    //  顶部
    [_topSeverLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(kViewMargin);
        make.top.equalTo(self).offset(35);
        make.height.equalTo(@14);
    }];
    
    
    [_topDateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_topSeverLab.mas_right).offset(kViewMargin);
        make.centerY.equalTo(_topSeverLab);
        make.height.equalTo(@20);
        make.width.equalTo(@137);
    }];
    
    //  底部
    [_bottomSeverLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.equalTo(_topSeverLab);
        make.top.equalTo(_topSeverLab.mas_bottom).offset(kViewMargin);
        make.bottom.equalTo(self).offset(-1*37);
    }];
    
    [_bottomDateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.width.equalTo(_topDateBtn);
        make.centerY.equalTo(_bottomSeverLab);
    }];

}

- (void)dropDwonButtonClick:(UIButton *)btn {
    NSLog(@"%s",__func__);
    if (self.block) {
        self.block(btn.tag);
    }
}

- (void)setStartTime:(NSString *)startTime {
    _startTime = startTime;
    [_topDateBtn setTitle:startTime forState:UIControlStateNormal];
    
//    [self layoutIfNeeded];
}

- (void)setEndTime:(NSString *)endTime {
    _endTime = endTime;
    [_bottomDateBtn setTitle:endTime forState:UIControlStateNormal];
//    [self layoutIfNeeded];
    
}

@end
